package com.itheima.tlias.Service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tlias.Mapper.EmpMapper;
import com.itheima.tlias.Service.EmpService;
import com.itheima.tlias.anno.Log;
import com.itheima.tlias.pojo.Emp;
import com.itheima.tlias.pojo.PageBean;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;


//    @Override
//    public PageBean page(Integer page, Integer pageSize){
//        PageBean pageBean=new PageBean();
//       pageBean.setTotal(empMapper.count());
//        Integer start=(page-1)*pageSize;
//        pageBean.setRows(empMapper.page(start,pageSize));
//        return pageBean;
//    }

    @Override
    public PageBean page(Integer page, Integer pageSize, String name, Short gender, LocalDate begin, LocalDate end) {

        PageHelper.startPage(page,pageSize);

        List<Emp> empList = empMapper.list(name,gender,begin,end);

        Page<Emp> p=(Page<Emp>) empList;

        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }

    @Override
    public void delete(List<Integer> ids){

            empMapper.delete(ids);

    }

    @Override
    public void insert(Emp emp){
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.insert(emp);
    }

    @Override
    public Emp getById(Integer id){
       Emp emp= empMapper.getById(id);
        return emp;
    }

    @Override
    public void update(Emp emp){
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.update(emp);
    }

    @Override
    public  Emp Login(Emp emp){
        Emp e=empMapper.Login(emp);
        return e;
    }

    @Override
    public Emp getByUsername(Emp emp) {
        empMapper.getByUsername(emp);
        return emp;
    }
}
